package io.renren.modules.jxgkphone.controller;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.renren.common.utils.R;
import io.renren.modules.jxgkphone.entity.ClassAttendance;
import io.renren.modules.jxgkphone.service.StudentSignInService;
import io.renren.modules.jxgkphone.tempEntity.TempUpdateAttend;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/studentsSignIn")
public class StudentSignInController {

    @Autowired
    StudentSignInService studentSignInService;

    @RequestMapping("/{classCourseId}/getMySignIn")
    public R UpdateClassStatus(@PathVariable("classCourseId") String classCourseId){

        String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
        ClassAttendance classAttendance=studentSignInService.getMySignIn(classCourseId,username);
        return   R.ok().put("data",classAttendance);
    }

    @RequestMapping("/sginIn")
    public R sginIn(@RequestBody String jsonStr){
        Gson _gson=new Gson();
        Map<String, Object> params = _gson.fromJson(jsonStr, new TypeToken<Map<String, Object>>() {
        }.getType());
        String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
        params.put("username",username);
        ClassAttendance classAttendance= studentSignInService.saveSginIn(params);
        return   R.ok().put("data",classAttendance);
    }

}
